home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / DELPHI32 / COMPNENT / CCS32 / CSFPMAIN.PAS < prev    next >
Pascal/Delphi Source File  |  1996-06-24  |  3KB  |  106 lines

  1. unit CSFPMain;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, ExtCtrls, CSFrmPnl, CSNoteBk,
  8.   CSFPPat, CSFPHist, CSFPProc, CSFPCode, CSFPComp;
  9.  
  10. type
  11.   TMainForm = class(TForm)
  12.     csNotebook1: TcsNotebook;
  13.     csFormPanel1: TcsFormPanel;
  14.     csFormPanel2: TcsFormPanel;
  15.     csFormPanel3: TcsFormPanel;
  16.     csFormPanel4: TcsFormPanel;
  17.     csFormPanel5: TcsFormPanel;
  18.     procedure csNotebook1PageChanged(Sender: TObject);
  19.     procedure FormCreate(Sender: TObject);
  20.     procedure csNotebook1PageChanging(Sender: TObject; NewIndex: Integer;
  21.       var AllowChange: Boolean);
  22.   private
  23.     { Private declarations }
  24.     FPrevPage: Integer;
  25.   public
  26.     { Public declarations }
  27.   end;
  28.  
  29. var
  30.   MainForm: TMainForm;
  31.  
  32. implementation
  33.  
  34. {$R *.DFM}
  35.  
  36. procedure TMainForm.csNotebook1PageChanged(Sender: TObject);
  37. var Form: TForm;
  38.     FPanel: TcsFormPanel;
  39. begin
  40.   { Create form for current page }
  41.   with TcsPage(csNotebook1.Pages.Objects[csNotebook1.PageIndex]) do
  42.     if (ControlCount > 0) and (Controls[0] is TcsFormPanel) then
  43.       FPanel := TcsFormPanel(Controls[0])
  44.     else
  45.       FPanel := nil;
  46.  
  47.   if (FPanel <> nil) and (FPanel.Form = nil) then
  48.   begin
  49.     case csNotebook1.PageIndex of
  50.       0:  Form := TPatForm.Create(Self);
  51.       1:  Form := THistForm.Create(Self);
  52.       2:  Form := TProcForm.Create(Self);
  53.       3:  Form := TCodeForm.Create(Self);
  54.       4:  Form := TCompForm.Create(Self);
  55.     else
  56.       Form := nil;
  57.     end;
  58.     if Form <> nil then
  59.       FPanel.Form := Form;
  60.   end;
  61.  
  62.   { Release form for previous page }
  63.   if FPrevPage >= 0 then
  64.   begin
  65.     with TcsPage(csNotebook1.Pages.Objects[FPrevPage]) do
  66.       if (ControlCount > 0) and (Controls[0] is TcsFormPanel) then
  67.         FPanel := TcsFormPanel(Controls[0])
  68.       else
  69.         FPanel := nil;
  70.     if (FPanel <> nil) and (FPanel.Form <> nil) then
  71.     begin
  72.       { destroy the form and release it's memory }
  73.       FPanel.Form.Close;
  74.       FPanel.Form.Release;
  75.       FPanel.Form := nil; { necessary to force re-create when reselected }
  76.     end;
  77.   end;
  78.   FPrevPage := csNotebook1.PageIndex;
  79. end;
  80.  
  81. procedure TMainForm.FormCreate(Sender: TObject);
  82. begin
  83.   FPrevPage := -1;
  84.   csNotebook1PageChanged(Sender);
  85. end;
  86.  
  87. { This code is not essential but is needed if you want to prevent
  88.   changes to another page when the form's CloseQuery function
  89.   returns False.
  90. }
  91. procedure TMainForm.csNotebook1PageChanging(Sender: TObject;
  92.   NewIndex: Integer; var AllowChange: Boolean);
  93. var FPanel: TcsFormPanel;
  94. begin
  95.   { Check that current page's form can be closed before allowing change }
  96.   with TcsPage(csNotebook1.Pages.Objects[csNotebook1.PageIndex]) do
  97.     if (ControlCount > 0) and (Controls[0] is TcsFormPanel) then
  98.       FPanel := TcsFormPanel(Controls[0])
  99.     else
  100.       FPanel := nil;
  101.   if (FPanel <> nil) and (FPanel.Form <> nil) then
  102.     AllowChange := FPanel.Form.CloseQuery;
  103. end;
  104.  
  105. end.
  106.